package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Apply;
import com.EpidemicPrevention.service.ApplyServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/ApplyController")
public class ApplyController {

    @Autowired
    private ApplyServiceImpl applyService;

    /*
     *添加用户
     * @Prama user 实体类
     * @return
     */
    @GetMapping("/addApply")
    @ResponseBody
    @CrossOrigin
    public JSON addApply(Apply apply) {
        return applyService.addApply (apply);
    }


    @GetMapping("/updataApply")
    @ResponseBody
    @CrossOrigin
    public  JSON updataApply(Apply apply){
        return applyService. updateApply (apply);
    }

    /**
     * 删除用户
     *
     * @param v_id
     * @return
     */
    @GetMapping("/deleteApply")
    @ResponseBody
    @CrossOrigin
    public JSON deleteApply(int v_id) {
        return applyService.deleteApply (v_id);
    }



    /**
     * 查看用户
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/queryApply")
    @ResponseBody
    @CrossOrigin
    public JSON queryApply(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "");
        json.put("count",applyService.queryApply (0, 100000).size());
        json.put("data", applyService.queryApply (page2, limit));
        return json;
    }
}
